<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<link rel="stylesheet" href="/css/font.css">
		<link rel="stylesheet" href="/css/xadmin.css">
		<style>
			form {
				margin-top: 10px;
			}
			
		</style>
	</head>
	<body>
		<form class="layui-form" id="saveTeacheForm">
			<div class="layui-form-item">
				<label class="layui-form-label"><font color="red" size="3">*</font>教师编号</label>
				<div class="layui-input-block">
					<input type="number" name="teacherNo" required lay-verify="required|teacherNo" placeholder="5-20位数字，且不能出现空格" autocomplete="off" class="layui-input">
					<input type="hidden" name="orgId" th:attr="value=${orgId}">
				</div>
			</div>
			<div class="layui-form-item">
                <label class="layui-form-label"><font color="red" size="3">*</font>姓名</label>
                <div class="layui-input-block">
                    <input type="text" name="teacherName" required lay-verify="required|teacherName" placeholder="2-15个字符，且不能出现空格" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><font color="red" size="3">*</font>身份证号</label>
                <div class="layui-input-block">
                    <input type="text" name="idNumber" required lay-verify="required|idNumber" placeholder="请输入正确的身份证号" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
			    <label class="layui-form-label"><font color="red" size="3">*</font>性别</label>
			    <div class="layui-input-block">
				  <input type="radio" name="teacherSex" value="2" title="男" checked>
				  <input type="radio" name="teacherSex" value="1" title="女">
				</div>
			  </div>
	        <div class="layui-form-item">
               <label class="layui-form-label"><font color="red" size="3">*</font>出生日期</label>
               <div class="layui-input-block">
                   <input type="text" name="teacherBirth" required lay-verify="required" id="teacherBirth" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
               </div>
            </div>
			<div class="layui-form-item">
			   <label class="layui-form-label"><font color="red" size="3">*</font>政治面貌</label>
			   <div class="layui-input-block">
			       <select name="politics" lay-verify="required">
					<option value=""></option>
					<option value="中共党员">中共党员</option>
					<option value="共青团员">共青团员</option>
					<option value="群众">群众</option>
				  </select>
			   </div>
			</div>
			<div class="layui-form-item">
			   <label class="layui-form-label"><font color="red" size="3">*</font>民族</label>
			   <div class="layui-input-block">
			       <input type="text" name="nation" required lay-verify="required|nation" placeholder="1-5个字符，且不能出现空格" autocomplete="off" class="layui-input">
			   </div>
			</div>
			<div class="layui-form-item">
			   <label class="layui-form-label"><font color="red" size="3">*</font>籍贯</label>
			   <div class="layui-input-block">
			       <input type="text" name="homeplace" required lay-verify="required|homeplace" placeholder="1-10个字符，且不能出现空格" autocomplete="off" class="layui-input">
			   </div>
			</div>
			<div class="layui-form-item">
			   <label class="layui-form-label">毕业学校</label>
			   <div class="layui-input-block">
			       <input type="text" name="graduateSchool" required lay-verify="graduateSchool" placeholder="1-15个字符，且不能出现空格" autocomplete="off" class="layui-input">
			   </div>
			</div>
			<div class="layui-form-item">
			   <label class="layui-form-label"><font color="red" size="3">*</font>入校日期</label>
			   <div class="layui-input-block">
			       <input type="text" name="startTime" required lay-verify="required|startTime" id="startTime" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
			   </div>
			</div>
			<div class="layui-form-item">
			   <label class="layui-form-label"><font color="red" size="3">*</font>学历</label>
			   <div class="layui-input-block">
			       <select name="graduateStatus" lay-verify="required">
						<option value=""></option>
						<option value="专科">专科</option>
						<option value="本科">本科</option>
						<option value="硕士研究生">硕士研究生</option>
						<option value="博士研究生">博士研究生</option>
			       </select>
			   </div>
			</div>
			<div class="layui-form-item">
			   <label class="layui-form-label">通讯地址</label>
			   <div class="layui-input-block">
			       <input type="text" name="address" required lay-verify="address" placeholder="1-20个字符，且不能出现空格" autocomplete="off" class="layui-input">
			   </div>
			</div>
			<div class="layui-form-item">
			   <label class="layui-form-label">备注</label>
			   <div class="layui-input-block">
			       <textarea name="remark1" placeholder="1-50个字符" class="layui-textarea"></textarea>
			   </div>
			</div>
			<!-- <div class="layui-form-item">
				<label class="layui-form-label">排序号</label>
				<div class="layui-input-block">
					<input type="number" name="sort" required lay-verify="required|sort" placeholder="1-5位数字，降序排列" autocomplete="off" class="layui-input" value="1">
				</div>
			</div> -->
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn" lay-submit lay-filter="formDemo" type="button">立即提交</button>
				</div>
			</div>
		</form>
		
		<script type="text/javascript" src="/js/jquery.min.js"></script>
        <script type="text/javascript" src="/js/xadmin.js"></script>
        <script type="text/javascript" src="/lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="/js/vue.min.js"></script>
        <script type="text/javascript" src="/js/jquery.form.js"></script>
		<script>
			layui.use(['form', 'layedit', 'laydate'], function(){
				var form = layui.form
				,layer = layui.layer
				var laydate = layui.laydate;
				laydate.render({
					elem: '#teacherBirth' //指定元素
			    });
				laydate.render({
					elem: '#startTime', //指定元素
				});
				var reg_graduateSchool = /^[\S]{1,15}$/;
				var reg_address = /^[\S]{1,20}$/;
				var reg_remark1 = /^[\S]{1,50}$/;
				form.verify({
					// 教师编号
					teacherNo: [/^[\S]{5,20}$/,'5-20位数字，且不能出现空格'],
					// 姓名
					teacherName: [/^[\S]{2,15}$/,'2-15个字符，且不能出现空格'],
					// 身份证号
					idNumber: [/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/,'请输入正确的身份证号'],
					// 民族
					nation : [/^[\S]{1,10}$/,'1-5个字符，且不能出现空格'],
					// 籍贯
					homeplace : [/^[\S]{1,10}$/,'1-10个字符，且不能出现空格'],
					// 毕业学校
					graduateSchool: function(value) {
						if(value.length > 0 && !reg_graduateSchool.test(value)) {
							return "1-15个字符，且不能出现空格";
						}
					},
					// 通讯地址
					address: function(value) {
						if(value.length < 1) {
							return "1-20个字符，且不能出现空格";
						}
					},
					// 备注
					remark1: function(value) {
						if(value.length > 0 && !reg_remark1.test(value)) {
							return "1-50个字符";
						}
					},
					
					sort: function(value) {
						if(value.length > 5) {
							return "1-5位数字";
						}
					},
				});
			
				//监听提交
				form.on('submit(formDemo)', function(data){
					$.ajax({
                        url : "/sys/teacher/info/saveTeacher",
                        type : "post",
                        data : $("#saveTeacheForm").serializeArray(),
                        success : function(result) {
                            if (result.state) {
                                layer.msg('保存成功！', {icon: 1,time: 1000}, function(){
                                    // 1.先得到当前iframe层的索引
                                    var index = parent.layer.getFrameIndex(window.name); 
                                    // 2.再执行关闭 
                                    parent.layer.close(index); 
                                    // 调用父页面的方法
                                    window.parent.updateSaveData();
                                });
                            } else {
                                layer.msg(""+result.msg, {icon: 5});
                            }
                        }
                    });
				});
			});
		</script>
	</body>
</html>
